<style>
  #sendBookBack-add {
    padding: 20px 25px 25px 0;
  }

  #sendBack-add .layui-treeSelect .ztree li a, .ztree li span {
    margin: 0 0 2px 3px !important;
  }
</style>
<div class="layui-fluid" id="sendBookBack-add" title="退书信息登记">
  <form class="layui-form" action="" lay-filter="sendBookBack-add-form">
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">图书名称：</label>
      <div class="layui-input-block">
        <input type="hidden" name="indentid" autocomplete="off" class="layui-input">
        <input type="hidden" name="backstatus" autocomplete="off" class="layui-input">
        <input type="hidden" name="bookstatus" autocomplete="off" class="layui-input">
        <input type="hidden" name="indentedStatus" autocomplete="off" class="layui-input">
        <input type="text" name="bookname" id="bookname" maxlength="20" lay-verify="required"
               autocomplete="off" class="layui-input" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">图书类型：</label>
      <div class="layui-input-block">
        <input type="text" name="booktype" id="booktype" autocomplete="off" class="layui-input"
               lay-verify="required" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">出版社：</label>
      <div class="layui-input-block">
        <input type="text" name="pubid" id="pubid" minlength="1" maxlength="10" lay-verify="range"
               autocomplete="off" class="layui-input" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">价格：</label>
      <div class="layui-input-block">
        <input type="text" name="bookmoney" id="bookmoney" autocomplete="off" class="layui-input"
               lay-verify="required" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">退书数量：</label>
      <div class="layui-input-block">
        <input type="text" name="number" id="number" autocomplete="off" class="layui-input"
               lay-verify="required" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">退书客户：</label>
      <div class="layui-input-block">
        <input type="text" name="principal" autocomplete="off" class="layui-input"
               lay-verify="required" readonly>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">下单时间：</label>
      <div class="layui-input-block">
        <input type="text" name="indentdate" id="indentdate" autocomplete="off" class="layui-input"
               lay-verify="required" disabled>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">退书时间：</label>
      <div class="layui-input-block">
        <input type="text" name="backdate" id="backdate" autocomplete="off" class="layui-input"
               lay-verify="required" disabled>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label febs-form-item-require">退书说明：</label>
      <div class="layui-input-block">
        <input type="text" name="message" autocomplete="off" class="layui-input"
               lay-verify="required">
      </div>
    </div>
    <div style="display: flex;justify-content: flex-end;font-weight: bolder;font-size: 20px">退书总价：
      <input name="totalmoney" style="border:none;width: 50px;line-height:20px" readonly>元
    </div>
    <div class="layui-form-item febs-hide">
      <button class="layui-btn" lay-submit="" lay-filter="sendBookBack-add-form-submit" id="submit"></button>
      <button type="reset" class="layui-btn" id="reset"></button>
    </div>
  </form>
</div>

<script data-th-inline="javascript">
  layui.use(['febs', 'form', 'validate', 'laydate'], function () {
    var $ = layui.$,
        laydate = layui.laydate,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        sendBookBack = [[${sendBookBack}]],
        $view = $('#sendBookBack-add'),
        validate = layui.validate;

    form.verify(validate);
    form.render();

    initSendBookBackValue();

    laydate.render({
      elem: '#indentdate',
      type: 'datetime'
    });

    laydate.render({
      elem: '#backdate',
      type: 'datetime'
    });

    function initSendBookBackValue() {
      form.val("sendBookBack-add-form", {
        "indentid": sendBookBack.indentid,
        "pubid": sendBookBack.pubid,
        "backstatus": sendBookBack.backstatus,
        "bookstatus": sendBookBack.bookstatus,
        "indentedStatus": sendBookBack.indentedStatus,
        "bookname": sendBookBack.bookname,
        "bookmoney": sendBookBack.bookmoney,
        "booktype": sendBookBack.booktype,
        "number": sendBookBack.number,
        "principal": sendBookBack.principal,
        "indentdate": sendBookBack.indentdate,
        "backdate": sendBookBack.backdate,
        "totalmoney": sendBookBack.totalmoney,
      });
    }

    form.on('submit(sendBookBack-add-form-submit)', function (data) {
      data.field.backmessage === $('#backmessage').val;
      if (data.field.backstatus === "1") {
        febs.alert.warn("该书籍正在报损申请中。");
        return false;
      }
      if (data.field.backstatus === "2") {
        febs.alert.warn("该订单申请报损退书，已被驳回。");
        return false;
      }
      if (data.field.backstatus === "3") {
        febs.alert.warn("该书籍正在退书申请中。");
        return false;
      }
      if (data.field.backstatus === "0") {
        if (data.field.bookstatus === '0') {
          febs.post(ctx + 'sendBack/sendBackOne/', data.field, function () {
            layer.closeAll();
            febs.alert.success("尊敬的用户" + data.field.principal + ' ，已成功为您取消订单。');
            $('#febs-bookIndent').find('#query').click();
          });
        } else {
          febs.post(ctx + 'sendBack/sendBackTwo/', data.field, function () {
            layer.closeAll();
            febs.alert.success("尊敬的用户" + data.field.principal + ' ，退书请求已发送。');
            $('#febs-bookIndent').find('#query').click();
          });
        }
      }
      return false;
    });
  });
</script>